//
//  ViewController.m
//  CustomDemo
//
//  Created by 余意 on 2016/12/20.
//  Copyright © 2016年 余意. All rights reserved.
//

#import "ViewController.h"


#import "WaterfallViewController.h"
#import "ParallaxViewController.h"
#import "MoveCellViewController.h"

@interface ViewController () <UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic,strong) UITableView * customTableView;

@property (nonatomic,strong) NSArray * textArray ;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self.customTableView reloadData];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSArray *)textArray
{
    if (!_textArray)
    {
        _textArray = @[@"瀑布流（WaterFall）",@"滚动视差（Parallax）",@"拖拽排序（MoveCell）",@"暂时没有"];
    }
    return _textArray;
}

- (UITableView *)customTableView
{
    if (!_customTableView)
    {
        _customTableView = [UITableView new];
        _customTableView.dataSource = self;
        _customTableView.delegate = self;
        _customTableView.rowHeight = 80;
        _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_customTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
        [self.view addSubview:_customTableView];
        _customTableView.frame = self.view.bounds;
    }
    return _customTableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.textArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [self.customTableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = self.textArray[indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
    cell.backgroundColor = RANDOMCOLOR;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        WaterfallViewController * WFVC = [[WaterfallViewController alloc]init];
        [self.navigationController pushViewController:WFVC animated:YES];
    }
    else if (indexPath.row == 1)
    {
        ParallaxViewController * PVC = [[ParallaxViewController alloc]init];
        [self.navigationController pushViewController:PVC animated:YES];
    }
    else if (indexPath.row == 2)
    {
        MoveCellViewController * MCVC = [[MoveCellViewController alloc]init];
        [self.navigationController pushViewController:MCVC animated:YES];
    }
}


@end
